<?php 

	require "config.php";
	
	session_start();
	
	if(isset($_POST['upload-btn'])){
		
		$file_name = $_FILES['upload-file']['name'];
		$tmp_name = $_FILES['upload-file']['tmp_name'];
		
		$mappa = getcwd();
		
		$eleresi_ut = $mappa."\\users\\".$_SESSION['username']."\\".$file_name;
		
		if(move_uploaded_file($tmp_name, $eleresi_ut)){
			
			$conn->query("INSERT INTO videos VALUES(id, $_SESSION[id], '$_POST[name]', '$_POST[description]', '$file_name', '', 0)");
			
			echo "<script>alert('Sikeres fájl feltöltés!')</script>";
			
		}
		else{
			echo "<script>alert('A videó feltöltése sikertelen!')</script>";
		}
		
	}

?>
<!DOCTYPE html>
<html lang="hu">

	<head>
		
		<!-- TITLE -->
		<title>Főoldal</title>
		
		<!-- CSS -->
		<link rel="stylesheet" href="css/style.css">
		
	</head>
	<body>
	
		<!-- NAV -->
		<?php require "nav.php"; ?>
		
		<!-- CONTENT -->
		<form method="post" enctype="multipart/form-data" class="reglog">
		
			<label class="form-header">Videó feltöltése</label>
			
			<input type="text" name="name" placeholder="Videó neve">
			
			<textarea name="description" placeholder="Videó leírása" rows="5"></textarea>
		
			<input type="file" name="upload-file">
			
			<input type="submit" name="upload-btn">
		
		</form>
	
	</body>
	
	<?php require "footer.php"; ?>
	
</html>